package org.siam.impl.data.formatting.formatters {

	import flexunit.framework.Assert;
	import flexunit.framework.TestCase;
	
	import org.siam.impl.data.formatting.formatters.NumberFormatter;
	import org.siam.utils.RuntimeError;
	
	public class NumberFormatterTest extends TestCase {
		
		private var formatter:NumberFormatter = new NumberFormatter(); 
		
		private function testValidFormatString(formatString:String, value:Object, expected:String):void {
			formatter.formatString = formatString;
			Assert.assertEquals(formatter.format(value), expected);
		}
		
		private function testInvalidFormatString(formatString:String):void {
			try {
				formatter.formatString = formatString;
				Assert.fail("An error should have been thrown for formatString " + formatString);
			} catch (e:RuntimeError) {
			}
		}
		
		public function testFormatString():void {
			
			// test valid formatString
			testValidFormatString(null, -12345.6789, "-12,345.6789");
			testValidFormatString("", -12345.6789, "-12,345.6789");
			testValidFormatString("-####", -12345.6789, "-12345");
			testValidFormatString("-####", -12345.6789, "-12345");
			testValidFormatString("####", -12345.6789, "(12345)");
			testValidFormatString("####", 12345.6789, "12345");
			testValidFormatString("#,###", 12345.6789, "12,345");
			testValidFormatString("#,###+", 12345.6789, "12,346");
			testValidFormatString("#,###-", 12345.6789, "12,345");
			testValidFormatString("#,###~", 12345.6789, "12,346");
			testValidFormatString("#,###.##", 12345.6789, "12,345.67");
			testValidFormatString("-#,###.##~", -12345.6789, "-12,345.68");
			
			// test invalid formatString
			testInvalidFormatString("-#.##.##");
		}
	}
}